package stdio.costa.moca.pdf;

import java.util.Iterator;

import com.aspose.words.Cell;
import com.aspose.words.DocumentBuilder;
import com.aspose.words.NodeCollection;
import com.aspose.words.NodeType;
import com.aspose.words.Row;
import com.aspose.words.Table;

public class ReplaceTextWithImageInNestedCellVisitor extends AbstractReplaceTextWithImageVisitor implements TableVisitor {

	public ReplaceTextWithImageInNestedCellVisitor(String text, byte[] image, DocumentBuilder builder) {
		super(text, image, builder);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public void visit(Cell cell) throws Exception {
		if (cell.getRange().getText().contains(text)) {
			NodeCollection<Table> tables = cell.getChildNodes(NodeType.TABLE, true);
			Iterator<Table> iterator = tables.iterator();
			while(iterator.hasNext()) {
				Table table = iterator.next();
				if(table.getRange().getText().contains(text)) {
					TableVisitableDecorator visitable = new TableVisitableDecorator(table);
					visitable.accept(new ReplaceTextWithImageInCellVisitor(text, image, builder));
				}
			}
		}
	}
	
	@Override
	public void visit(Row row) throws Exception {
	}

	@Override
	public void visit(Table table) throws Exception {
	}
}
